﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Tong;

public partial class js组件_js拖拽_js拖动操作触发事件 : System.Web.UI.Page
{


    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    /// <summary>
    /// 显示下拉菜单的表
    /// </summary>
    DataTable NewDt = new DataTable();

    /// <summary>
    /// sql语言
    /// </summary>
    string sql = "";

    string Rid = "";
    public string xmlcont = "";//输出的菜单
    protected void Page_Load(object sender, EventArgs e)
    {

        xmlcont = "";
        #region 开始处理各个节点
        NewDt.Columns.Add("东东");
        NewDt.Columns.Add("Conts");
        ShowTree(0);
        for (int i = 0; i < NewDt.Rows.Count; i++)
        {
            xmlcont += "<div id=\"Menu_Tree" + NewDt.Rows[i]["东东"].ToString() + "\" " + outputEvtstr(NewDt.Rows[i]["东东"].ToString()) + ">" + NewDt.Rows[i]["Conts"].ToString() + (ISNewsColumn(NewDt.Rows[i]["东东"].ToString()) ? "<span style=\"color:#ff0000;\">新闻</span>" : "").ToString() + "</div>";
        }
        #endregion
        Response.Charset = "utf-8";
        Response.ContentType = "text/html";
    }

    protected string outputEvtstr( string Cid)
    {

        if (ISNewsColumn(Cid))
        {
            return "onmousedown=\"MyMove.Move('Menu_Tree" + Cid + "',event,1,'Menu_Main','cu(\\\'Menu_Tree" + Cid + "\\\')');\" style=\"cursor:move;\"";
        }
        else
        {
            return "";   
        }

    }

    /// <summary>
    /// 看看这个传入的ID是不是新闻栏目
    /// </summary>
    /// <param name="Cid"></param>
    /// <returns></returns>
    protected bool ISNewsColumn(string Cid)
    {
        DataTable Tmptab = TextData.SqlataSet("select  CX_Column_LX from [CX_Column] where CX_Column_id=" + Cid + "").Tables[0];
       try
       {
           if (Tmptab.Rows[0][0].ToString() == "1")
           {
               return true;
           }
           else
           {
               return false;
           }
       }
       catch
       {
           return false;
       }
    }

    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);
            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);
            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;
        }
    }
}
//Divs[i].Attributes.GetNamedItem("id").Value.Replace("MenuTree_")
